﻿using System;
using System.Data;
using System.Data.Common;
using System.Globalization;
using Gammar.Price.ObjectModel;
using Longbow.Data;

namespace Gammar.Price.DataAccess
{
    /// <summary>
    /// 
    /// </summary>
    public partial class SearchContent : ReaderCommand<SearchContentEntity>
    {   
        /// <summary>
        /// 
        /// </summary>            
        protected override CommandType CommandType
        {
            get { return CommandType.Text; }
        }

        private string _criteria;
        
        /// <summary>
        /// 
        /// </summary>
        public string Criteria
        {
            get { return _criteria; }
            set { _criteria = value; }
        }
        
        /// <summary>
        /// 
        /// </summary>
        protected override string CommandText
        {
            get
            {
                string sql = "select * from Openclass_SearchContent";
                if (!string.IsNullOrEmpty(Criteria))
                    sql = string.Format(CultureInfo.InvariantCulture, "{0} {1}", sql, Criteria);
                return sql;
            }        
        }

        /// <summary>
        /// 
        /// </summary>            
        protected override void AddParameters(DbParameterCollection parameters, DBAccess db)
        {

        }

        /// <summary>
        /// 
        /// </summary>            
        protected override SearchContentEntity ParseRow(DbDataReader reader)
        {
            SearchContentEntity obj = new SearchContentEntity();
            obj.Oc_id = (Guid?)DBAccess.ToObjectValue(reader["Oc_id"]);
            obj.Typename = (string)DBAccess.ToObjectValue(reader["Typename"]);
            obj.Title = (string)DBAccess.ToObjectValue(reader["Title"]);
            obj.Promotepricevar = (string)DBAccess.ToObjectValue(reader["Promotepricevar"]);
            obj.Promotepricemon = (decimal?)DBAccess.ToObjectValue(reader["Promotepricemon"]);
            obj.Presideunit = (string)DBAccess.ToObjectValue(reader["Presideunit"]);
            obj.Srcweb = (string)DBAccess.ToObjectValue(reader["Srcweb"]);
            obj.Introduction = (string)DBAccess.ToObjectValue(reader["Introduction"]);
            obj.Recommindex = (int?)DBAccess.ToObjectValue(reader["Recommindex"]);
            obj.Counter = (int?)DBAccess.ToObjectValue(reader["Counter"]);
            obj.Url = (string)DBAccess.ToObjectValue(reader["Url"]);
            obj.Type = (Guid?)DBAccess.ToObjectValue(reader["Type"]);
            return obj;
        }
    }
}